Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
	''' <summary>
	''' Strongly-typed collection for the PollVotes class.
	''' </summary>
	<Serializable> _
	Public Partial Class PollVotesCollection 
	Inherits ActiveList(Of PollVotes, PollVotesCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the PollVotes table.
	''' </summary>
	<Serializable> _
	Public Partial Class PollVotes 
	Inherits ActiveRecord(Of PollVotes)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
		
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("PollVotes", TableType.Table, DataService.GetInstance("ClubStarterKitData"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarVoteId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarVoteId.ColumnName = "VoteId"
                colvarVoteId.DataType = DbType.Guid
                colvarVoteId.MaxLength = 0
                colvarVoteId.AutoIncrement = false
                colvarVoteId.IsNullable = false
                colvarVoteId.IsPrimaryKey = true
                colvarVoteId.IsForeignKey = false
                colvarVoteId.IsReadOnly = false
                
                
                schema.Columns.Add(colvarVoteId)
                
                Dim colvarUserId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarUserId.ColumnName = "UserId"
                colvarUserId.DataType = DbType.Guid
                colvarUserId.MaxLength = 0
                colvarUserId.AutoIncrement = false
                colvarUserId.IsNullable = false
                colvarUserId.IsPrimaryKey = false
                colvarUserId.IsForeignKey = false
                colvarUserId.IsReadOnly = false
                
                
                schema.Columns.Add(colvarUserId)
                
                Dim colvarPollAnswerId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarPollAnswerId.ColumnName = "PollAnswerId"
                colvarPollAnswerId.DataType = DbType.Guid
                colvarPollAnswerId.MaxLength = 0
                colvarPollAnswerId.AutoIncrement = false
                colvarPollAnswerId.IsNullable = false
                colvarPollAnswerId.IsPrimaryKey = false
                colvarPollAnswerId.IsForeignKey = true
                colvarPollAnswerId.IsReadOnly = false
                
                
				colvarPollAnswerId.ForeignKeyTableName = "PollAnswers"
                
                schema.Columns.Add(colvarPollAnswerId)
                
                Dim colvarCreationDate As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarCreationDate.ColumnName = "CreationDate"
                colvarCreationDate.DataType = DbType.DateTime
                colvarCreationDate.MaxLength = 0
                colvarCreationDate.AutoIncrement = false
                colvarCreationDate.IsNullable = false
                colvarCreationDate.IsPrimaryKey = false
                colvarCreationDate.IsForeignKey = false
                colvarCreationDate.IsReadOnly = false
                
                
                schema.Columns.Add(colvarCreationDate)
                
                Dim colvarPollId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarPollId.ColumnName = "PollId"
                colvarPollId.DataType = DbType.Guid
                colvarPollId.MaxLength = 0
                colvarPollId.AutoIncrement = false
                colvarPollId.IsNullable = false
                colvarPollId.IsPrimaryKey = false
                colvarPollId.IsForeignKey = false
                colvarPollId.IsReadOnly = false
                
                
                schema.Columns.Add(colvarPollId)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("ClubStarterKitData").AddSchema("PollVotes",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("VoteId")> _
        Public Property VoteId As Guid 
			Get
				Return GetColumnValue(Of Guid)("VoteId")
			End Get
		    
			Set
				SetColumnValue("VoteId", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("UserId")> _
        Public Property UserId As Guid 
			Get
				Return GetColumnValue(Of Guid)("UserId")
			End Get
		    
			Set
				SetColumnValue("UserId", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("PollAnswerId")> _
        Public Property PollAnswerId As Guid 
			Get
				Return GetColumnValue(Of Guid)("PollAnswerId")
			End Get
		    
			Set
				SetColumnValue("PollAnswerId", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("CreationDate")> _
        Public Property CreationDate As DateTime 
			Get
				Return GetColumnValue(Of DateTime)("CreationDate")
			End Get
		    
			Set
				SetColumnValue("CreationDate", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("PollId")> _
        Public Property PollId As Guid 
			Get
				Return GetColumnValue(Of Guid)("PollId")
			End Get
		    
			Set
				SetColumnValue("PollId", Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
			    
	    
		
		
		
		
		
	    
	    #Region "ForeignKey Methods"
	    
		''' <summary>
		''' Returns a PollAnswers ActiveRecord object related to this PollVotes
		''' </summary>
		Public Property PollAnswers() As Data.PollAnswers
			Get
				Return Data.PollAnswers.FetchByID(Me.PollAnswerId)
			End Get
			Set
				SetColumnValue("PollAnswerId", Value.PollAnswerId)
			End Set
		End Property
	    
	    #End Region
	    
		
	    
	    'no ManyToMany tables defined (0)
	    
		
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varVoteId As Guid,ByVal varUserId As Guid,ByVal varPollAnswerId As Guid,ByVal varCreationDate As DateTime,ByVal varPollId As Guid)
			Dim item As PollVotes = New PollVotes()
			
            item.VoteId = varVoteId
            
            item.UserId = varUserId
            
            item.PollAnswerId = varPollAnswerId
            
            item.CreationDate = varCreationDate
            
            item.PollId = varPollId
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varVoteId As Guid,ByVal varUserId As Guid,ByVal varPollAnswerId As Guid,ByVal varCreationDate As DateTime,ByVal varPollId As Guid)
			Dim item As PollVotes = New PollVotes()
		    
                item.VoteId = varVoteId
				
                item.UserId = varUserId
				
                item.PollAnswerId = varPollAnswerId
				
                item.CreationDate = varCreationDate
				
                item.PollId = varPollId
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared VoteId As String = "VoteId"
            
            Public Shared UserId As String = "UserId"
            
            Public Shared PollAnswerId As String = "PollAnswerId"
            
            Public Shared CreationDate As String = "CreationDate"
            
            Public Shared PollId As String = "PollId"
            
		End Structure
		#End Region
	End Class
End Namespace
